package com.tingyuge.base.jdk.io.aio;

import java.util.Scanner;

/**
 * @Created by xiaodao
 */
public class AioClient {
    private static String DEFAULT_HOST = "127.0.0.1";
    public final static int PORT = 12345;

    private static AioClientHandler aioClientHandler ;

    public static boolean sendMsg(String msg){
        if(msg.equalsIgnoreCase("q")){
            return false;
        }

        aioClientHandler.sendMsg(msg+System.getProperty("lien.sparator"));
        return true;
    }
    public static synchronized void start(){
        if(aioClientHandler!=null)
            return;
        aioClientHandler = new AioClientHandler(DEFAULT_HOST,PORT);
        new Thread(aioClientHandler,"Client").start();


        }

    public static void main(String[] args) {
        AioClient.start();
        System.out.println("请输入信息:");
        Scanner scanner = new Scanner(System.in);
        while(AioClient.sendMsg(scanner.nextLine()));
    }
}




